<template>
  <div class="dimission-box">
    <el-form ref="form" @submit.native.prevent label-width="100px" class="top-search-box">
      <el-row class="row">
        <el-col :span="8">
            <el-form-item label="昵称">
                <el-input v-model="searchParams.nickname" placeholder="请输入" clearable></el-input>
            </el-form-item>
        </el-col>
        <el-col :span="16">
            <el-button size="large" type="warning" @click="resetFn" class="default-button f-right">重置</el-button>
            <el-button v-if="$route.query.key" size="large" type="primary" @click="getInfo('')" class="default-button f-right m-r-m">查询</el-button>
        </el-col>
      </el-row>
    </el-form>
    <div class="split-box">
        <el-table :data="tableData" style="width: 100%" class="noPaddingHead">
            <el-table-column label="昵称" align="left" prop="name"></el-table-column>
            <el-table-column label="手机号" align="left" prop="phone"></el-table-column>
            <el-table-column label="组织名称" align="left" prop="orgName"></el-table-column>
            <el-table-column label="职位" align="left" prop="positionName"></el-table-column>
            <el-table-column label="技能标签" align="left" prop="">
              <template slot-scope="scope">
                  <span v-for="(item,index) in scope.row.tagList" :key="item.primaryKey">
                    {{item.tagName}}
                    <span v-if="index < scope.row.tagList.length - 1">，</span>
                  </span>
              </template>
              
            </el-table-column>
            <el-table-column label="操作" align="left">
                <template slot-scope="scope">
                    <el-button v-if="scope.row.status === 1" type="text" @click="disableBtn(scope.row)" class="default-button warning">禁用</el-button>
                    <el-button v-if="scope.row.status !== 1" type="text" @click="enableBtn(scope.row)" class="default-button warning">启用</el-button>
                    <el-button type="text" @click="userCancel(scope.row)" class="default-button danger">注销</el-button>
                </template>
            </el-table-column>
        </el-table>

        <Pagination @change="pageChange" :total="total" />
    </div>

  </div>
</template>
<script>
import { requestTips,askDialog } from "../../../assets/util"
import { apiDimissionList,apiDimissionBan,apiDimissionLogout,apiDimissionEnable } from "../../../api";

export default {
  props:{
    infoData:{
      type:Object,
      default:()=>{
        return {}
      }
    }
  },
  data() {
    return {
      searchParams: {
        nickname: ''
      },
      organizeList:[],
      total: 0,
      pageSize: 10,
      currentPage: 1,
      tableData:[],
    };
  },
  created() {
    // 获取默认的企业key
    if (!this.$route.query.key && localStorage.getItem('userEnterpriseid') && this.$route.query.isAdd != 1) {
      this.$route.query.key = localStorage.getItem('userEnterpriseid')
    }
  },

  mounted() {
    if (this.$route.query.key) {
      this.getInfo()
    }
  },

  methods: {
    //table数据源
    async getInfo(type) {
        let res = await apiDimissionList({
            pageSize:this.pageSize,
            currentPage:type ? this.currentPage : 1,
            nickname:this.searchParams.nickname || null,
            bizType: "rent_auth_enterprise",
            enterpriseid:this.$route.query.key
        })
        this.tableData = res.rows || []
        this.total = res.total || 0
    },
    // 禁用
    disableBtn (item) {
        askDialog("是否禁用该员工？",async () => {
            const res = await apiDimissionBan({ userKey: item.userKey })
            requestTips(res,()=>{
              this.getInfo("more")
            })
        })
    },
    // 启用
    enableBtn (item) {
        askDialog("是否启用该员工？",async () => {
            const res = await apiDimissionEnable({ userKey: item.userKey })
            requestTips(res,()=>{
              this.getInfo("more")
            })
        })
    },
    // 注销
    async userCancel (item) {
        askDialog("是否注销？注销后将无法恢复，请谨慎操作！",async () => {
            const res = await apiDimissionLogout({ userKey: item.userKey })
            requestTips(res,()=>{
              this.getInfo("more")
            })
        })
    },
    //分页
    pageChange(e) {
      this.currentPage = e.currentPage;
      this.pageSize = e.pageSize;
      this.getInfo('more');
    },
    //重置
    resetFn(){
        this.searchParams.nickname = ''
        this.currentPage = 1
        this.pageSize = 10
        this.getInfo();
    }
  },
};
</script>
<style lang="scss" scoped>
.dimission-box{
    .top-search-box{
        padding: 16px;
    }
    .split-box{
        padding: 0 25px;
    }
}
</style>